package com.javaweb.admin.controller;

import com.javaweb.admin.entity.SOResaleInvoice;
import com.javaweb.admin.query.ReturnQuery;
import com.javaweb.admin.service.IReturnOrderService;
import com.javaweb.admin.vo.returnorder.OrderReturnDto;
import com.javaweb.common.annotation.Log;
import com.javaweb.common.enums.LogType;
import com.javaweb.common.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/return")
public class ReturnController {

    @Autowired
    private IReturnOrderService returnOrderService;
    @GetMapping("/index")
    public JsonResult index(ReturnQuery query) {
        try {
            return returnOrderService.getReturnOrderList(query);
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error(e.getMessage());
        }



    }

    @GetMapping("/ssbk")
    public JsonResult ssbk() {
        try {
            return returnOrderService.getSSBKList();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error(e.getMessage());
        }
    }

    @GetMapping("/saleorder")
    public JsonResult saleorder(ReturnQuery query) {
        try {
            return returnOrderService.getReturnSaleOrderList(query);
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error(e.getMessage());
        }
    }

    @GetMapping("/secondsale")
    public JsonResult secondsale(ReturnQuery query) {
        try {
            return returnOrderService.getSecondSaleList(query);
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error(e.getMessage());
        }
    }

    @GetMapping("/secondsalestock")
    public JsonResult secondsalestock(ReturnQuery query) {
        try {
            return returnOrderService.getSecondSaleStockList(query);
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error(e.getMessage());
        }
    }

    @GetMapping("/secondsalegroupstock")
    public JsonResult secondsalegroupstock(ReturnQuery query) {
        try {
            return returnOrderService.getSecondSaleGroupStockList(query);
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error(e.getMessage());
        }
    }

    @GetMapping("/secondsaleinvoice")
    public JsonResult secondsaleinvoice(ReturnQuery query) {
        try {
            return returnOrderService.getSecondSaleInvoiceList(query);
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error(e.getMessage());
        }
    }

    @GetMapping("/storelist")
    public JsonResult storelist() {
        try {
            return returnOrderService.getStoreList();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error(e.getMessage());
        }
    }

    @GetMapping("/orderdetail/{cgeneralhid}")
    public JsonResult orderdetail(@PathVariable("cgeneralhid") String cgeneralhid){
        return returnOrderService.getOrderDetail(cgeneralhid);
    }

    @GetMapping("/saleorderdetail/{csaleorderid}")
    public JsonResult saleorderdetail(@PathVariable("csaleorderid") String csaleorderid){
        return returnOrderService.getSaleOrderDetail(csaleorderid);
    }

    @GetMapping("/orderinvoice/{csaleorderid}")
    public JsonResult orderinvoice(@PathVariable("csaleorderid") String csaleorderid){
        return returnOrderService.getOrderInvoiceDetail(csaleorderid);
    }

    @GetMapping("/ordercheck/{csaleorderid}")
    public JsonResult ordercheck(@PathVariable("csaleorderid") String csaleorderid){
        return returnOrderService.getOrderCheckDetail(csaleorderid);
    }

    @GetMapping("/saleordercheck/{csaleorderid}")
    public JsonResult saleordercheck(@PathVariable("csaleorderid") String csaleorderid){
        return returnOrderService.getSaleOrderCheckDetail(csaleorderid);
    }

    @GetMapping("/resalelist/{csaleorderbid}")
    public JsonResult resalelist(@PathVariable("csaleorderbid") String csaleorderbid){
        return returnOrderService.getResaleList(csaleorderbid);
    }
    @GetMapping("/instockchecklist/{csaleinvoicebid}")
    public JsonResult instockchecklist(@PathVariable("csaleinvoicebid") String csaleinvoicebid){
        return returnOrderService.getInstockCheckList(csaleinvoicebid);
    }


    @PostMapping("/savereturn")
    public JsonResult savereturn(@RequestBody OrderReturnDto orderReturn){
        return returnOrderService.saveOrderReturn(orderReturn);
    }

    @PostMapping("/savesalereturn")
    public JsonResult savesalereturn(@RequestBody OrderReturnDto orderReturn){
        return returnOrderService.saveSaleOrderReturn(orderReturn);
    }

    @Log(title = "再销新增", logType = LogType.INSERT)
    @PostMapping("/saveresale")
    public JsonResult saveresale(@RequestBody SOResaleInvoice[] resaleInvoices){
        return returnOrderService.saveResaleInvoice(resaleInvoices);
    }

    @Log(title = "再销删除", logType = LogType.DELETE)
    @PostMapping("/delresale/{csaleinvoicebid}")
    public JsonResult delresale(@PathVariable("csaleinvoicebid") String csaleinvoicebid){
        return returnOrderService.delResaleInvoice(csaleinvoicebid);
    }
    @Log(title = "再销删除", logType = LogType.DELETE)
    @PostMapping("/delinstcok/{csaleinvoicebid}/{cgeneralbid}")
    public JsonResult delresale(@PathVariable("csaleinvoicebid") String csaleinvoicebid,@PathVariable("cgeneralbid") String cgeneralbid){
        return returnOrderService.delResaleInstock(csaleinvoicebid,cgeneralbid);
    }

}
